package com.hot100.easy;

/**
 * @ClassName Demo07
 * @Description
 * @Author zt
 * @Date 16:21 2022/6/9
 * @Version 1.0
 **/
public class Demo07 {

    public static void main(String[] args) {

    }

    public boolean isSymmetric(TreeNode root) {
            if(root==null){
                return true;
            }
        return dfs(root.left,root.right);
    }

    private boolean dfs(TreeNode left, TreeNode right) {
        if(left==null&&right==null){
            return true;
        }else if(left==null||right==null||right.val!=left.val){
            return false;
        }else {
            return  dfs(left.right,right.left)&&dfs(left.left,right.right);
        }
    }

    /**
     * Definition for a binary tree node.
     *
     */
     public class TreeNode {
         int val;
         TreeNode left;
         TreeNode right;
         TreeNode() {}
         TreeNode(int val) { this.val = val; }
         TreeNode(int val, TreeNode left, TreeNode right) {
             this.val = val;
             this.left = left;
             this.right = right;
         }
     }

}